<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
<html  xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>条款文件导入</title>
	<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
	<script src="<%=path%>/js/jquery.divbox.js" type="text/javascript"></script>
	<script type="text/javascript">
	var startP = 1;
	
$(document).ready(function() {
	//上传条款文件事件
	$("#buttonUpload").click(function(){
		$.openLoading();
		var fileNameStr = $('#fileToUpload').val();
		fileNameStr = fileNameStr+"";
		var lastDotIndex = fileNameStr.lastIndexOf(".");
		var lastGunIndex = fileNameStr.lastIndexOf("\\");
		if(lastDotIndex==-1){
			$.closeLoading();
			$.message("error","请选择扩展名为 .docx 的文件上传");
			return;
		}else{
			var extName = fileNameStr.substring(lastDotIndex+1, fileNameStr.length);
			if(extName.toLowerCase() =="doc"){
				$.closeLoading();
				$.message("error","仅支持docx文档的转换与导入，请将此文档在word或wps中另存为.docx格式（请勿直接重命名，直接重命名后内容格式仍未改变，导入会出现错误）");
				return;
			}
			
			if(extName.toLowerCase() != "docx"){
				$.closeLoading();
				$.message("error","请选择扩展名为 .docx 的文件上传");
				return;
			}
			var fileName = fileNameStr.substring(lastGunIndex +1, lastDotIndex);
			/* $.dialog1("warning","确认添加" + fileName + "条款文件？"){
				onCancel:return;
			} */
		}
		//存储前先确定，是否为更新
			$.ajax({
					url : '<%=path%>/prodManage/isRiskFileExist',
					type : 'POST',
					async : true,
					data:{riskCode : fileName},
					dataType:'json',
					success:function(result){
						$.closeLoading();
						if(result.result=='success'){
							$.ajaxFileUpload({
						        url:'<%=path%>/prodManage/riskFileUpload',
						        fileElementId :'fileToUpload',//file控件id
						        dataType: 'json',
						        success : function (data){
						        	$.closeLoading();
						        	if(data.result=="error"||data.result=="fail"){
						        		$.dialog({
							    			width: 358,
							    			top:40,
							    			modal:true,
							    			Close:true,
							    			cancel:null,
							    			content: data.message
							    		});
							        	return;
						        	}else{
						        		$.dialog({
							    			width: 358,
							    			top:40,
							    			modal:true,
							    			Close:true,
							    			cancel:null,
							    			content: "存储成功！ 条款代码：" + fileName + " ."
							    		});
						        	}
						        	if($.validate(data)) return;
						        	queryAgentMtInfo(1);
						        }
							});
						}else{
							$.dialog({
								type: "warn",
								content: "已存在条款文件，确认更新？",
								onOk: function() {
									$.openLoading();
									$.ajaxFileUpload({
								        url:'<%=path%>/prodManage/riskFileUpload',
								        fileElementId :'fileToUpload',//file控件id
								        dataType: 'json',
								        success : function (data){
								        	$.closeLoading();
								        	if(data.result=="error"||data.result=="fail"){
								        		$.dialog({
									    			width: 358,
									    			top:40,
									    			modal:true,
									    			Close:true,
									    			cancel:null,
									    			content: data.message
									    		});
									        	return;
								        	}else{
								        		$.dialog({
									    			width: 358,
									    			top:40,
									    			modal:true,
									    			Close:true,
									    			cancel:null,
									    			content: "更新成功！ 条款代码：" + fileName + " ."
									    		});
								        	}
								        	if($.validate(data)) return;
								        }
									});
								},
							onCancel:function(){
								return ;
							}
							})	
						}
					}
				})
		
		
		
		
		

	});
	
	queryRiskContent(1);
});
	//displayPage：当前页码
	function queryRiskContent(displayPage){
		var riskCode = $("#riskCode").val();
		var riskName = $("#riskName").val();
		loadRiskContent({current:displayPage,size:10,riskCode:riskCode,riskName:riskName});

	}
	
	
	
	//加载分页
	function loadRiskContent(param){
		var jsonDate;
		if(null != param && null != param.current){
			var str = "";
			var strReg = "[0-9]{4}-[0-9]{2}-[0-9]{2}";
			var startDate = param.startDate;
			var endDate = param.endDate;
			if(null != startDate && "" != startDate){
				if(startDate.match(strReg)==null){
					$.message("error", "您输入的定义起期格式不正确，格式为:YYYY-MM-DD");
					return;
				}
			}
			if(null != endDate && "" != endDate){
				if(endDate.match(strReg)==null){
					$.message("error", "您输入的定义止期格式不正确，格式为:YYYY-MM-DD");
					return;
				}
			}
			jsonDate =param;
			
		}else{
			jsonDate={current:1,size:10};
		}
		$.openLoading();
		$.ajax({
			url : "prodManage/loadRiskContent",
			type : 'POST',
			async : true,
			dataType:'json',
			data:jsonDate,
			success : function(page) {
				 	$.closeLoading();
					if($.validate(page))
						return;
					startP = page.current;
					var lastbutton = "<a href='javascript:void(0)' onClick='previewRiskContent(this);return false'>预览</a>";
					var tableContent = creatTable("RISK_CODE,CORE_RISK_NAME,LAST_OPERATE_TIME",page,lastbutton);
					var tableObj = $("#riskContentInfos");
					tableObj.find("tbody").remove();
					tableObj.append(tableContent);
					var strPage = creatChannelPage(startP,6,page.maxPage,"96");
					var pageDIV = $("#txproductpageDIV");
					pageDIV[0].innerHTML="";
					pageDIV.append(strPage);
			}	
		})	
	}
	

function previewRiskContent(obj){
	//点击预览窗口，展示条款文件；
	
	var riskCode = $(obj).parent('td').parent('tr')[0].childNodes[0].innerHTML;
	var param = {riskCode : riskCode};
	
	$.ajax({
		url : "prodManage/previewRiskContent",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(subPage) {
			 	$.closeLoading();
				$.dialog({
	    			width: 1000,
	    			height:600,
	    			modal:true,
	    			Close:true,
	    			cancel:null,
	    			content: subPage.message,
	    		});
				
			
				$(".xxDialog").css("overflow","scroll");
				return ;
		}	
	})
}
	
	
	</script>
</head>
<body >
	<div class="current">
           <table class="current_table_1">
              <tbody>
                <tr class="f2">
                  <td>
                    <img src="./images/current_1.jpg">
                  </td>
                  <td class="current_table_1_td">
                    <img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
                      <span style=" color:#136bab; ">扫码出单管理
                      <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>条款文件导入
                  </span>
                  </td>
                  <td><img src="./images/current_3.jpg"></td>
              </tr>
           </tbody>
         </table>
      </div>
		
		<table class="table_02" id="table">
			<tr>
				<td>
					<table border="1" class="table_02" style="height:50px">
						<tr>
			  				<td width="60%" nowrap="nowrap"><input  id="fileToUpload" name="myfiles" type='file' size='20'/><a href="javascript:void(0);" id="buttonUpload">&nbsp;&nbsp;导入条款文件&nbsp;&nbsp;</a>
			  				
			  				<span style="color:red"> *只支持.docx文档的转换  ， 请以 条款代码.docx 的格式命名文件  (例如：11500006.docx) </span>
			  				</td>
			  			</tr>
					</table>
				</td>
			</tr>
		</table>
		
		
				<table class="table_02" id="table">
			<tr>
				<td>
					<table class="search_table">
						<tr height="30px">
							<td width="20%" height="30">险种代码：
								<input name="txt3" id="riskCode" type="text" class="input_text" value="">
							</td>
							<td width="20%" height="30">险种名称：
								<input name="txt4" id="riskName" type="text" class="input_text" value="">
							</td>
							</td>
						</tr>
						<tr height="30px">
							<td style="text-align: center;" colspan="5" width="100%" height="30">
								<input type="button" class="input_button_1" id="searchBtn" value="查询" onClick="queryRiskContent(1)" />&nbsp;
							    <input type="button" class="input_button_1" id="searchBtn" value="重置" onClick="vreset()" />
							</td>
						</tr> 
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table class="search_table">
					</table>
				</td>
			</tr>
			<tr>
				<td>
					<table id="riskContentInfos" class="content_table_1">
						<thead>
							<tr class="f1">
								<th style="width:10%;">条款代码</th>
								<th style="width:25%;">条款名称</th>
								<th style="width:15%;">修改时间</th>
								<th style="width:14%;">操作</th>
							</tr>
						</thead>
						<tbody>
						</tbody>
					</table>
					<div id="txproductpageDIV" class="page"></div>
				</td>
			</tr>
		</table>
		
		
		
		<div id="Loading" style="display:none" align="center">
			<img src="./images/loading.gif" />
		</div>
		
	<!-- 结束 -->
</body>
</html>